#include "NXTbt.h"

int BtOpen(char *btAddress) {
	struct sockaddr_rc addr={0};
	int nxtsocket, status;

	nxtsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

	addr.rc_family = AF_BLUETOOTH;
	addr.rc_channel = (uint8_t) 1;
	str2ba(btAddress, &addr.rc_bdaddr);

	status = connect (nxtsocket, (struct sockaddr *)&addr, sizeof(addr));
	if (status == 0){
		return nxtsocket;
	}
	else {
		return -1;
	}
}

void BtClose(int socket){
	close(socket);
}

